package com.mingqi.enetconnected.primary.mytask.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.primary.mytask.activity.AddGasToolActivity;
import com.mingqi.enetconnected.primary.mytask.activity.PutTableActivity;
import com.mingqi.enetconnected.primary.mytask.listener.PutTableListener;
import com.mingqi.enetconnected.util.DeviceUtils;
import com.mingqi.enetconnected.util.resource.ResourceUtils;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * @author li
 * @version 1.0
 * @describe
 * @WeChat 18571658038
 * @date 2018/9/6 星期四.
 */

public class DeviceInfoAdapter extends BaseQuickAdapter<String,BaseViewHolder> {

    private Context mContext;

    public DeviceInfoAdapter(Context context,List<String> data) {
        super(R.layout.item_table_tool,data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {

        helper.setText(R.id.tv_title,item);
        final ImageView ivExpend = helper.getView(R.id.iv_expend);
        helper.addOnClickListener(R.id.tv_put_table);

        switch (item) {
            case "表具信息" :

                final RecyclerView rvExpandTable = helper.getView(R.id.rv_expand);

                List<String> expandList = new ArrayList<>();
                for (int i = 0; i < 2; i++) {

                    expandList.add("");
                }

                final TableToolAdapter tableAdapter = new TableToolAdapter(expandList,mContext);
                rvExpandTable.setAdapter(tableAdapter);
                rvExpandTable.setLayoutManager(new LinearLayoutManager(mContext));
                rvExpandTable.addItemDecoration(new HorizontalDividerItemDecoration.Builder(mContext)
                        .colorResId(R.color.space)
                        .size(DeviceUtils.dp2px(mContext,10))
                        .build());
                rvExpandTable.setVisibility(View.GONE);

                helper.getView(R.id.tv_title).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        int visibility = rvExpandTable.getVisibility();
                        if(visibility == View.VISIBLE) {

                            rvExpandTable.setVisibility(View.GONE);
                            ivExpend.setImageResource(R.drawable.ic_expand_false);
                        } else {

                            rvExpandTable.setVisibility(View.VISIBLE);
                            ivExpend.setImageResource(R.drawable.ic_expand_true);
                        }
                    }
                });

                helper.getView(R.id.tv_put_table).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent = new Intent(mContext, PutTableActivity.class);
                        mContext.startActivity(intent);
                    }
                });

                break;
            case "燃气具" :

                helper.setText(R.id.tv_put_table, ResourceUtils.getString(R.string.new_increased));
                final RecyclerView rvExpandGas = helper.getView(R.id.rv_expand);

                List<String> gasList = new ArrayList<>();
                gasList.add("");

                final GasToolAdapter gasAdapter = new GasToolAdapter(gasList,mContext);
                rvExpandGas.setAdapter(gasAdapter);
                rvExpandGas.setLayoutManager(new LinearLayoutManager(mContext));
                rvExpandGas.addItemDecoration(new HorizontalDividerItemDecoration.Builder(mContext)
                        .colorResId(R.color.space)
                        .size(DeviceUtils.dp2px(mContext,10))
                        .build());
                rvExpandGas.setVisibility(View.GONE);

                helper.getView(R.id.tv_title).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        int visibility = rvExpandGas.getVisibility();
                        if(visibility == View.VISIBLE) {

                            rvExpandGas.setVisibility(View.GONE);
                            ivExpend.setImageResource(R.drawable.ic_expand_false);

                        } else {

                            rvExpandGas.setVisibility(View.VISIBLE);
                            ivExpend.setImageResource(R.drawable.ic_expand_true);
                        }
                    }
                });

                helper.getView(R.id.tv_put_table).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent = new Intent(mContext, AddGasToolActivity.class);
                        mContext.startActivity(intent);
                    }
                });

                break;
            default:

                break;
        }
    }
}
